package pl.edu.mimuw.irs.rcp.controller.editor.workflow.handler;

import java.io.Serializable;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Display;

import pl.edu.mimuw.irs.core.model.design.net.IRSNode;
import pl.edu.mimuw.irs.core.model.design.net.IRSNodeCopier;
import pl.edu.mimuw.irs.rcp.util.dnd.IRSNodeTransfer;

public class CopyHandler extends AbstractNodeHandler {

	// *** Attributes

	// *** Methods
	
	@Override
	protected Object execute(ExecutionEvent event, CommandStack stack, IRSNode node)
			throws ExecutionException {

		Clipboard clipboard = new Clipboard(Display.getCurrent());
		IRSNodeTransfer transfer = IRSNodeTransfer.getInstance();
		
		IRSNode copy = node.getCopier().copy(IRSNodeCopier.OMIT_NET_ASSIGNMENT);
		
		clipboard.setContents(new Object[][] { new Serializable[] { copy } }, new Transfer[] { transfer });
		
		return null;
	}
}
